package com.lc202309;

import java.util.*;

/**
 * Description:
 *
 * @Create 2023/9/27 22:43
 * @Version 1.0
 */
public class Solution1333 {
    public List<Integer> filterRestaurants(int[][] restaurants, int veganFriendly, int maxPrice, int maxDistance) {
        List<Integer> list = new ArrayList<>();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < restaurants.length; i++) {
            if (veganFriendly == 1 && restaurants[i][2] == 0) {
                continue;
            }
            if (restaurants[i][3] > maxPrice) {
                continue;
            }
            if (restaurants[i][4] <= maxDistance) {
                list.add(restaurants[i][0]);
                map.put(restaurants[i][0], i);
            }
        }
        list.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                if (restaurants[map.get(o2)][1] != restaurants[map.get(o1)][1]) {
                    return restaurants[map.get(o2)][1] - restaurants[map.get(o1)][1];
                }
                return o2 - o1;
            }
        });
        return list;
    }
}
